﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration.Provider;
using System.Runtime.Caching;

namespace Shop.Infrastructure.Caching
{
    public abstract class ObjectCacheProvider : CacheProvider
    {
        public abstract ObjectCache InnerCache
        {
            get;
        }

        public override bool Add(string key, object value, CacheItemPolicy policy, string regionName = null)
        {
            return InnerCache.Add(key, value, policy, regionName);
        }

        public override void Clear(string regionName = null)
        {
            List<string> keyList = new List<string>();
            foreach (var kv in InnerCache)
            {
                keyList.Add(kv.Key);
            }
            foreach (string key in keyList)
            {
                InnerCache.Remove(key, regionName);
            }
        }

        public override bool Contains(string key, string regionName = null)
        {
            return InnerCache.Contains(key, regionName);
        }

        public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor(IEnumerable<string> keys, string regionName = null)
        {
            return InnerCache.CreateCacheEntryChangeMonitor(keys, regionName);
        }

        public override DefaultCacheCapabilities DefaultCacheCapabilities
        {
            get { return InnerCache.DefaultCacheCapabilities; }
        }

        public override object Get(string key, string regionName = null)
        {
            return InnerCache.Get(key, regionName);
        }

        public override CacheItem GetCacheItem(string key, string regionName = null)
        {
            return InnerCache.GetCacheItem(key, regionName);
        }

        public override IDictionary<string, object> GetValues(IEnumerable<string> keys, string regionName = null)
        {
            return InnerCache.GetValues(keys, regionName);
        }

        public override object Remove(string key, string regionName = null)
        {
            return InnerCache.Remove(key, regionName);
        }

        public override void Set(string key, object value, CacheItemPolicy policy, string regionName = null)
        {
            InnerCache.Set(key, value, policy, regionName);
        }
    }
}
